import numpy as np
from skimage import io
import matplotlib.pyplot as plt
img = io.imread("galaxy-full.jpg")
r = img[:, :, 0]
g = img[:, :, 1]
b = img[:, :, 2]
img_full = np.stack((r, g, b), axis=-1)
fg, ax = plt.subplots(1, 5, figsize=(20, 5))
ax[0].imshow(img)
ax[0].set_title('original img')
ax[1].imshow(r, cmap='gray')
ax[1].set_title('R')
ax[2].imshow(g, cmap='gray')
ax[2].set_title('G')
ax[3].imshow(b, cmap='gray')
ax[3].set_title('B')
ax[4].imshow(img_full)
ax[4].set_title('R+G+B')
plt.tight_layout()  # 调整子图位置
plt.savefig('out.png', bbox_inches='tight')  # 以最紧凑模式保存显示内容到out.png
plt.show()